package TextBookCode.unit2.unit2_3;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

public class ProductList extends Observable {
    private List<String> productList = null;
    private static ProductList instance;


    public static ProductList getInstance() {
        if (instance == null) {
            instance = new ProductList();
            instance.productList = new ArrayList();
        }

        return instance;
    }

    public void addProductListObserver(Observer observer) {
        this.addObserver(observer);
    }

    public void addProudct(String newProduct) {
        this.productList.add(newProduct);
        System.err.println("产品列表新增了产品：" + newProduct);
        this.setChanged();
        this.notifyObservers(newProduct);
    }
}
